package com.guoyan.blockchain.component.model;

import com.alibaba.fastjson.JSONObject;

/**
 * @author yeym
 */
public class TxModel implements Model {
    private long time;
    private double weight;
    private double unitPrice;
    private double totalPrice;
    private String txNumber;
    private String marketName;
    private String businessName;
    private String ecrNumber;
    private String identification;
    private String ecrMac;


    @Override
    public Boolean verify() {
        //&& this.unitPrice != 0 && this.totalPrice != 0
        return this.time != 0 && this.weight != 0
                && this.txNumber != null && this.marketName != null && this.businessName != null && this.ecrNumber != null
                && this.identification != null && this.ecrMac != null;
    }

    @Override
    public Model fromJson(JSONObject jsonObject) {
        TxModel txModel = new TxModel();
        try {
            txModel.setTime(System.currentTimeMillis());
            txModel.setWeight(jsonObject.getDouble("weight"));
            txModel.setUnitPrice(jsonObject.getDouble("unitPrice"));
            txModel.setTotalPrice(jsonObject.getDouble("totalPrice"));
            txModel.setTxNumber(jsonObject.getString("txNumber"));
            txModel.setMarketName(jsonObject.getString("marketName"));
            txModel.setBusinessName(jsonObject.getString("businessName"));
            txModel.setEcrNumber(jsonObject.getString("ecrNumber"));
            txModel.setIdentification(jsonObject.getString("identification"));
            txModel.setEcrMac(jsonObject.getString("ecrMac"));
        } catch (Exception ignored) {
        }
        return txModel;
    }


    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public double getUnitPrice() {
        return unitPrice;
    }

    public void setUnitPrice(double unitPrice) {
        this.unitPrice = unitPrice;
    }

    public double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }

    public String getTxNumber() {
        return txNumber;
    }

    public void setTxNumber(String txNumber) {
        this.txNumber = txNumber;
    }

    public String getMarketName() {
        return marketName;
    }

    public void setMarketName(String marketName) {
        this.marketName = marketName;
    }

    public String getBusinessName() {
        return businessName;
    }

    public void setBusinessName(String businessName) {
        this.businessName = businessName;
    }

    public String getEcrNumber() {
        return ecrNumber;
    }

    public void setEcrNumber(String ecrNumber) {
        this.ecrNumber = ecrNumber;
    }

    public String getIdentification() {
        return identification;
    }

    public void setIdentification(String identification) {
        this.identification = identification;
    }

    public String getEcrMac() {
        return ecrMac;
    }

    public void setEcrMac(String ecrMac) {
        this.ecrMac = ecrMac;
    }


}
